#!/bin/bash

#---------------------------------------------------------------------
# Script  : preflight
#---------------------------------------------------------------------
# Purpose : Script that install the patient database 
#---------------------------------------------------------------------
# History :
#
# 12/2004 LS Creation
#---------------------------------------------------------------------

echo 'PATIENT INSTALLER - START PREFLIGHT SCRIPT'

# Echoes the script arguments
echo "The full path to the install package : $1"
echo "The full path to the install destination : $2"
echo "The mount point of the destination volume : $3"
echo "The root directory for the current system folder : $4"

repository="$1/Contents/Resources/.repository"
echo "my repository : $repository"

target="$2Applications/KDIS Mac OS X"
echo "my install destination : $target"

# Install the praticien.txt file into the /KDIS Mac OS X default folder
mkdir -p -m 777 "$target"
if [ -e "$target/praticien.txt" ] ; then
   echo 'The patient.txt file is already installed'
else
   install -c -o root -g admin -m 666 "$repository/praticien.txt" "$target/"
fi

# Intall the patient database
dbrepository="Sample Image DB"
if [ -e "$target/$dbrepository" ] ; then
   echo "The $dbrepository folder is already installed"
else
   cp -R "$repository/$dbrepository" "$target/"
   if [ -e "$target/$dbrepository" ] ; then
      chown -R root:admin "$target/$dbrepository"
      find "$target" -type d -exec chmod 777 {} \;
      find "$target" -type f -exec chmod 666 {} \;
      echo "The $dbrepository database is successfully installed"
   else
      echo "Fail to install the $dbrepository database"
      exit 1
   fi
fi

echo 'PATIENT INSTALLER - END PREFLIGHT SCRIPT'

exit 0
